<?php

namespace App\Http\Controllers\Backend\Dances;

use App\Http\Controllers\Backend\BackendController;
use App\Http\Models\Dances\DancesFrom;
use App\Http\Service\backend\Dances\DancesService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

/**
 * Class 课程列表控制器
 * @package App\Http\Controllers\Backend\Dances
 *
 */
class DancesController extends BackendController
{

    private $dancesService;
    private $request;

    public function __construct(DancesService $dancesService, Request $request) {
        $this->dancesService = $dancesService;
        $this->request = $request;
    }

    public function index() {
        $dancesList = $this->dancesService->dancesList($this->request);
        return view('backend.dances.index', [
            'dancesList' => $dancesList,
            'request' => $this->request
        ]);
    }

    public function create() {
        $userList = DB::table('users')->where(['status' => 1, 'delete' => 1, 'users_status' => 0])->get()->toArray();
        return view('backend.dances.create', ['userList' => $userList,'dances'=>DANCE]);
    }

    public function store(DancesFrom $dancesFrom) {
        $this->dancesService->store($dancesFrom);
        return redirect('admin/dances');
    }

    public function edit($id) {
        $dancesData = $this->dancesService->show($id);
        return view('backend.dances.update', [
            'dancesData' => $dancesData['dancesData'],
            'userData' => $dancesData['userData'],
            'dances'=>DANCE
        ]);
    }

    public function update(DancesFrom $dancesFrom, $id) {
        $this->dancesService->updateSave($dancesFrom, $id);
        return redirect('admin/dances');
    }

    public function destroy($id) {
        return $this->dancesService->remove($id);
    }

}
